package cn.hm.search.controller;

import cn.hm.common.response.Result;
import cn.hm.common.response.StatusCode;
import cn.hm.search.service.SkuEsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author Mxb
 * @version 1.0
 * @date 2020/10/3 15:33
 */
@RestController
@CrossOrigin
@RequestMapping("/search")
public class SkuEsController {
    @Autowired
    private SkuEsService skuEsService;

    /**
     * 数据导入
     * @return
     */
    @GetMapping("/import")
    public Result importData() {
        skuEsService.importData();
        return new Result(true, StatusCode.OK, "导入数据到索引库中成功!");
    }

    /**
     * 首页搜索框  实现方法
     * @param searchMap
     * @return
     */
    @GetMapping
    //                  允许参数为空
    public Map search(@RequestParam(required = false) Map<String,String> searchMap) {
        Map resultMap = skuEsService.search(searchMap);
        return resultMap;
    }

}
